﻿namespace FFF.Test.Framework.IM
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Http;
    using Ydm.LayIM.AspNetCore.Core.Application;

    /// <summary>
    /// IM用户获取
    /// </summary>
    public class IMUserFactory : ILayIMUserFactory
    {
        /// <summary>
        /// 业务方自定义用户ID
        /// </summary>
        /// <param name="context">httpContext</param>
        /// <returns>用户ID</returns>
        public string GetUserId(HttpContext context)
        {
            context.Session.TryGetValue("layim_uid", out byte[] userId);
            return userId == null ? null : Encoding.Default.GetString(userId);
        }
    }
}
